<div class="row">
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf" style="margin-top:-25px">
            <div class="widget-head am-cf">
                <div class="widget-title am-cf">代言人列表</div>
                <!-- 工具栏 -->
                <div class="page_toolbar am-margin-bottom-xs am-cf">
                    <div class="am-btn-group am-btn-group-xs">
                        <a class="am-btn am-btn-default am-btn-success"
                           href="<?= url('agent.user/add') ?>" style="margin-top:10px">
                            <span class="am-icon-plus"></span> 新增代言人
                        </a>
                        <div class="widget-head am-cf">
                            <div class="am-fl">授权免费代言人数量：<?= $amount['shouquan']?>个  剩余免费数量：<?= $amount['can']?>个</div>
                        </div>
                    </div>
                </div>
                <div class="am-scrollable-horizontal am-u-sm-12">
                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                        <thead>
                        <tr>
                            <th width="13">ID</th>
                            <th width="13">类型</th>
                            <th width="13">名称</th>
                            <th width="13">电话</th>
                            <th width="13">添加时间</th>
                            <th width="30">操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php if(!$list->isEmpty()):foreach($list as $item):?>
                            <tr>
                                <td class="am-text-middle">
                                    <p class="item-title">{{$item['agent_id']}}</p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title">
                                        <?php if ($item['type'] == 0)
                                            echo '品牌商';
                                        elseif($item['type'] == 1)
                                            echo '城市运营商';
                                        elseif($item['type'] == 2)
                                            echo '城市合伙人';
                                        else
                                            echo '代言人';
                                        ?>
                                    </p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title">
                                        <?= $item['real_name'] ?>
                                    </p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['company_tel'] ?></p>
                                </td>

                                <td class="am-text-middle"><?= format_time($item['create_time']) ?></td>
                                <td class="am-text-middle">
                                    <div class="tpl-table-black-operation">
                                        <?php if ($item['agent_check_status'] == 0):?>
                                            <a onclick="checkStatus('am-icon-trashqy','<?= $item['agent_id'] ?>')" class="j-delete tpl-table-black-operation-success"
                                               data-id="<?= $item['agent_id'] ?>">
                                                <i class="am-icon-trashqy"></i> 通过
                                            </a>
                                        <?php endif; ?>
                                        <?php if ($item['agent_check_status'] == 1 && $item['admin_check_status']==0)
                                            echo '待后台激活';
                                        ?>
                                        <?php if ($item['agent_check_status'] == 1 && $item['admin_check_status']==1)
                                            echo '已激活';
                                        ?>
                                        <a onclick="getInformation('<?= $item['real_name'] ?>','<?= url('agent.agent/getAgentInfo?agent_id='.$item['agent_id']) ?>','<?= $item['agent_id'] ?>')" class="j-delete tpl-table-black-operation-add"
                                           data-id="<?= $item['agent_id'] ?>">
                                            <i class="am-icon-trash"></i> 查看详情
                                        </a>
                                        <a onclick="updateInformation('<?= url('agent.agent/getAgentInfo?agent_id='.$item['agent_id']) ?>','<?= $item['agent_id'] ?>')" class="j-delete tpl-table-black-operation-del"
                                           data-id="<?= $item['agent_id'] ?>">
                                            <i class="am-icon-arrow-right"></i> 修改账户
                                        </a>
                                        <?php if ($item['active'] == 1&&$item['agent_check_status'] == 1 && $item['admin_check_status']==1): ?>
                                            <a onclick="checkoutStatus('am-icon-trashdj','<?= $item['agent_id'] ?>')" class="j-delete tpl-table-black-operation-del"
                                               data-id="<?= $item['agent_id'] ?>">
                                                <i class="am-icon-trashdj"></i> 冻结
                                            </a>
                                        <?php elseif ($item['active'] == 0&&$item['agent_check_status'] == 1 && $item['admin_check_status']==1): ?>
                                            <a onclick="checkoutStatus('am-icon-trashqy','<?= $item['agent_id'] ?>')" class="j-delete tpl-table-black-operation-success"
                                               data-id="<?= $item['agent_id'] ?>">
                                                <i class="am-icon-trashqy"></i> 启用
                                            </a>
                                        <?php endif; ?>

                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; else: ?>
                            <tr>
                                <td colspan="4" class="am-text-center">暂无记录</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="am-u-lg-12 am-cf">
                    <div class="am-fr"><?= $list->render() ?> </div>
                    <div class="am-fr pagination-total am-margin-right">
                        <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function getInformation(title,url,agentid){
        console.log(url)
        $('.j-delete').getinfo(title+"详情",url,'get',agentid);
    }
    //启用禁用
    function checkoutStatus(claickclass,agent_id){
        console.log(claickclass);
        $.ajax({
            type : "POST",
            url : "<?= url('agent.user/editUser') ?>",
            data : {agent_id:agent_id,claickclass:claickclass},
            success : function(result) {
                console.log(result.code)
                if(result.code==1){
                    url="<?= url('agent.user/index') ?>";
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1200,
                        shade: 0.5,
                        end: function () {
                            (url !== undefined && url.length > 0) ? window.location = url : window.location.reload();
                        }
                    });
                }else{
                    layer.msg('操作失败');
                }
            },
            error : function(e){
               layer.msg('操作失败')
            }
        });
    }
    //审核通过
    function checkStatus(claickclass,agent_id){
        $.ajax({
            type : "POST",
            url : "<?= url('agent.user/checkout') ?>",
            data : {agent_id:agent_id,claickclass:claickclass},
            success : function(result) {
                console.log(result.code)
                if(result.code==1){
                    url="<?= url('agent.user/index') ?>";
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1200,
                        shade: 0.5,
                        end: function () {
                            (url !== undefined && url.length > 0) ? window.location = url : window.location.reload();
                        }
                    });
                }else{
                    layer.msg('操作失败');
                }
            },
            error : function(e){
                layer.msg('操作失败')
            }
        });
    }
    function updateInformation(url,agentid){
        //console.log(url)
        $('.j-delete').getinfo('修改信息',url,'edit',agentid);
    }
</script>
